package com.share.finance.fund.web;

import com.share.common.common.Page;
import com.share.common.common.Result;
import com.share.finance.fund.model.db.RepaymentRecord;
import com.share.finance.fund.model.vo.RepaymentRecordAddOrUpdateReq;
import com.share.finance.fund.model.vo.RepaymentRecordPageReq;
import com.share.finance.fund.service.IRepaymentRecordService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 还款记录  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-08-21
 */
@RestController
@RequestMapping("/repayRecord")
public class RepaymentRecordController {

    @Autowired
    private IRepaymentRecordService repaymentRecordService;

    @ApiOperation(value = "分页列表")
    @RequestMapping(value = "/pageList")
    public Result<Page<RepaymentRecord>> pageList(RepaymentRecordPageReq req) {
        Page<RepaymentRecord> page = repaymentRecordService.pageList(req);
        return Result.success(page);
    }

    @ApiOperation("新增")
    @RequestMapping("/add")
    public Result add(RepaymentRecordAddOrUpdateReq req) {
        RepaymentRecord record = new RepaymentRecord();
        BeanUtils.copyProperties(req, record);
        return Result.bool(repaymentRecordService.save(record));
    }

    @ApiOperation("修改")
    @RequestMapping("/update")
    public Result update(RepaymentRecordAddOrUpdateReq req) {
        if (req.getId() == null) {
            return Result.failure("参数异常!");
        }
        RepaymentRecord record = new RepaymentRecord();
        BeanUtils.copyProperties(req, record);
        return Result.bool(repaymentRecordService.updateById(record));
    }

    @ApiOperation("删除")
    @RequestMapping("/delete")
    public Result delete(Integer id) {
        return Result.bool(repaymentRecordService.removeById(id));
    }
}
